# -*- coding: utf-8 -*-
"""
Created on Wed Jun 28 15:04:37 2017

@author: qiang.qian
"""
import json

import requests

values = {'name' : 'Michael Foord',
          'location' : 'Northampton',
          'language' : 'Python' }
check = 'http://ws.members.ctripcorp.com/userprofileservice/api/CheckHealth'
#data = urllib.parse.urlencode({'key':'value'}).encode("utf-8")
data = json.dumps(values)
headers = {'content-type': 'application/json'}
# https://docs.python.org/3/library/urllib.request.html#examples
# https://docs.aws.amazon.com/general/latest/gr/aws-ip-ranges.html
res = requests.post(url=check,data=data,headers=headers)
print(res.text)

# https://docs.python.org/3/library/json.html
#j = json.loads(res_body.decode("utf-8"))
#print(j)

# parse strings: 'ip_prefix' and 'region'
#for i in range(len(j['prefixes'])):
#	print("{0}\t{1}".format(j['prefixes'][i]['ip_prefix'], j['prefixes'][i]['region']))
#for prefix in j['prefixes']:
#	print("{0}\t{1}".format(prefix['ip_prefix'], prefix['region']))
